package online.listener;

import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import online.config.DelayedQueueConfig;
import online.config.TtlQueueConfig;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @Auther: 狼芒
 * @Date: 2021/11/7 17:45
 * @Descrintion: RabbitMq监听器，消费者
 * @version: 1.0
 */

@Slf4j
@Component
public class RabbitMqListener {

    /**
     * 报警消费者
     * @param message
     */
    @RabbitListener(queues = TtlQueueConfig.WARNING_QUEUE)
    public void receiveWarningQueue(Message message) {
        String msg = new String(message.getBody());
        log.error("报警消费者：当前时间：{},收到消息：{}", System.currentTimeMillis(), msg);
    }

    //消费消息,消费者过期消息
    @RabbitListener(queues = DelayedQueueConfig.DELAYED_QUEUE)
    public void receiveDelayQueue(Message message) {
        String msg = new String(message.getBody());
        log.error("当前时间：{},收到消费者过期消息：{}", System.currentTimeMillis(), msg);
    }

    //消费消息,消费死信队列
    @RabbitListener(queues = TtlQueueConfig.DEAD_LETTER_QUEUE)
    public void receiveDeadLetterSwitch(Message message, Channel channel) {
        String msg = new String(message.getBody());
        log.error("当前时间：{},收到死信队列的消息：{}", System.currentTimeMillis(), msg);

    }
}
